package com.spark.incoicings.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spark.incoicings.dao.CustomerMapper;
import com.spark.incoicings.service.CustomerService;
import com.spark.incoicings.vo.CustomerVO;
import com.spark.invoicings.entity.SaleCustomer;
import com.spark.invoicings.utils.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, SaleCustomer>implements CustomerService {

    @Resource
    private CustomerMapper customerMapper;
    /**
     * 带条件查询所有客户
     * 分页查询
     * @param map
     * @return
     */
    @Override
    public List<SaleCustomer>  selectCustomerAll(Map<String, Object> map) {
        List<SaleCustomer> saleCustomers = customerMapper.selectCustomerAll(map);
        saleCustomers.forEach(saleCustomer -> {
            CustomerVO customerVO = customerMapper.selectCustomerVo(saleCustomer.getCustomerId());
            saleCustomer.setCustomerRating(customerVO.getCustomerRating());
            saleCustomer.setCustomerSource(customerVO.getCustomerSource());
            saleCustomer.setBillingMethod(customerVO.getBillingMethod());
        });
        return saleCustomers;
    }


}
